package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.dao.StudyplanDao;
import com.coding.dao.UserDao;
import com.coding.pojo.Studyplan;
import com.coding.pojo.User;
import com.coding.service.StudyPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/8/16
 **/
@Service
public class StudyPlanImpl implements StudyPlanService {
    @Autowired
    UserDao userDao;
    @Autowired
    StudyplanDao studyplanDao;

    @Override
    public void getUserPlan(int user_id, BaseModel baseModel) throws Exception {
        User user = userDao.getuserbyuser_id(user_id);
        if (user == null) {
            baseModel.setFailure("该用户不存在，请检查账号是否正确");
            return;
        }
        List<Studyplan> studyplanList = studyplanDao.selectUserList(user_id);
        if (studyplanList != null) {
            baseModel.setSucceed("成功获得用户任务", studyplanList);
        } else {
            baseModel.setFailure("获得用户任务失败");
        }
    }

    @Override
    public void insertPlan(Studyplan studyplan, BaseModel baseModel) throws Exception {
        if (studyplanDao.insertSelective(studyplan) == 1) {
            baseModel.setSucceed("新增学习计划成功", studyplan);
        } else {
            baseModel.setFailure("新增学习计划失败");
        }
    }
}
